#!/bin/bash
cd ~/app-root/data/temp/Nexus4
#RRUrl=$(curl -s "http://downloads.resurrectionremix.com/oneplus3t/" |grep -o "RR-[A-Za-z0-9\.\-]\{1,\}\.zip" |tail -1)
#if ! grep -q "$RRUrl" RRUrl; then
#    echo $RRUrl > RRUrl
#    ~/app-root/data/github-sh/Nexus4/openload_uploader.sh remote "http://downloads.resurrectionremix.com/oneplus3t/$RRUrl" "OnePlus3T"
#fi
#Unofficial RR
RRUnFid=$(curl -s "https://www.androidfilehost.com/?a=show&w=files&flid=158998" |grep 'h4.*RR-N-[a-zA-Z0-9\.\-]\{1,\}\.zip<'|tail -1|grep -o 'fid=[0-9]\{1,\}')
if ! grep -q "$RRUnFid" RRUnFid; then
    echo $RRUnFid > RRUnFid
    RRUrl=$(curl -s "https://www.androidfilehost.com/libs/otf/mirrors.otf.php" --data "submit=submit&action=getdownloadmirrors&${RRUnFid}"|grep -o 'http[a-zA-Z0-9\/\\\.:\-]\{1,\}\.zip'|head -1|sed 's#\\\/#\/#g')
    ~/app-root/data/github-sh/Nexus4/openload_uploader.sh remote "$RRUrl" "OnePlus3T"
fi
RRUrl=$(curl -s "https://sourceforge.net/projects/resurrectionremix/files/oneplus-unified-3-3T/"|grep -o 'RR-[a-zA-Z0-9\.\-]*oneplus3[a-zA-Z0-9\.\-]*\.zip'|head -1)
if ! grep -q "$RRUrl" RRUrl; then
    remoteFile1="https://jaist.dl.sourceforge.net/project/resurrectionremix/oneplus-unified-3-3T/$RRUrl"
    remoteFile2="https://superb-sea2.dl.sourceforge.net/project/resurrectionremix/oneplus-unified-3-3T/$RRUrl"
    if curl -I "$remoteFile1"|grep -q ' 200 '; then
        echo $RRUrl > RRUrl
        ~/app-root/data/github-sh/Nexus4/openload_uploader.sh remote "$remoteFile1" "OnePlus3T"
    elif curl -I "$remoteFile2"|grep -q ' 200 '; then
        echo $RRUrl > RRUrl
        ~/app-root/data/github-sh/Nexus4/openload_uploader.sh remote "$remoteFile2" "OnePlus3T"
    fi
fi
